package com.cxso.example;

import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSONWriter;
import com.cxso.example.client.LocationClient;
import com.cxso.example.client.OcrClient;
import com.cxso.example.request.location.LocationVnoRouterPathRequest;
import com.cxso.example.request.location.LocationVnoTransTimeManageRequest;
import com.cxso.example.request.ocr.OcrBankCardRequest;
import com.cxso.example.response.location.LocationVnoRouterPathResponse;
import com.cxso.example.response.location.LocationVnoTransTimeManageResponse;
import com.cxso.example.response.ocr.OcrBankCardResponse;
import com.cxso.example.sdk.SdkClient;
import com.cxso.example.sdk.domain.Result;
import com.cxso.example.sdk.http.client.ClientManager;

import java.text.ParseException;
import java.text.SimpleDateFormat;

public class OpenExample {

    public static final SimpleDateFormat FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    //步骤一: 初始化客户端链接
    public static final ClientManager CLIENT_MANAGER = SdkClient.builder("服务域名地址", "clientId", "clientSecret");

    public static void main(String[] args) throws ParseException {
        //运输节点查询:实时位置示例
        locationVnoTransTimeManageExample();
        //运输行程服务:历史轨迹示例
        locationVnoRouterPathExample();
        //识别银行卡示例
        ocrBankCardExample();
    }

    //运输节点查询:实时位置示例
    private static void locationVnoTransTimeManageExample() {
        //步骤二: 选择服务
        LocationClient locationClient = CLIENT_MANAGER.use(LocationClient.class);
        //步骤三: 调用服务
        LocationVnoTransTimeManageRequest locationVnoTransTimeManageRequest = new LocationVnoTransTimeManageRequest();
        locationVnoTransTimeManageRequest.setVco("2");
        locationVnoTransTimeManageRequest.setVclN("冀AK7157");
        Result<LocationVnoTransTimeManageResponse> result = locationClient.locationVnoTransTimeManage(locationVnoTransTimeManageRequest);
        //步骤四: 拿到结果
        if (result.isSuccess()) {
            LocationVnoTransTimeManageResponse data = result.getData();
            System.out.println(JSONObject.toJSONString(data, JSONWriter.Feature.PrettyFormat));
        } else {
            System.out.println(result.getMsg());
        }
    }

    //运输行程服务:历史轨迹示例
    private static void locationVnoRouterPathExample() throws ParseException {
        //步骤二: 选择服务
        LocationClient locationClient = CLIENT_MANAGER.use(LocationClient.class);
        //步骤三: 调用服务
        LocationVnoRouterPathRequest locationVnoRouterPathRequest = new LocationVnoRouterPathRequest();
        locationVnoRouterPathRequest.setVco("2");
        locationVnoRouterPathRequest.setVclN("冀AK7157");
        locationVnoRouterPathRequest.setStartTime(FORMATTER.parse("2024-12-01 10:47:06"));
        locationVnoRouterPathRequest.setEndTime(FORMATTER.parse("2024-12-02 17:47:06"));
        Result<LocationVnoRouterPathResponse> result = locationClient.locationVnoRouterPath(locationVnoRouterPathRequest);
        //步骤四: 拿到结果
        if (result.isSuccess()) {
            LocationVnoRouterPathResponse data = result.getData();
            System.out.println(JSONObject.toJSONString(data, JSONWriter.Feature.PrettyFormat));
        } else {
            System.out.println(result.getMsg());
        }
    }

    //识别银行卡示例
    private static void ocrBankCardExample() {
        //步骤二: 选择服务
        OcrClient ocrClient = CLIENT_MANAGER.use(OcrClient.class);
        //步骤三: 调用服务
        Result<OcrBankCardResponse> result = ocrClient.ocrBankCard(new OcrBankCardRequest() {{
            setUrl("https://img1.baidu.com/it/u=4133249545,341559632&fm=253&fmt=auto&app=138&f=JPEG?w=674&h=500");
        }});
        //步骤四: 拿到结果
        if (result.isSuccess()) {
            OcrBankCardResponse data = result.getData();
            System.out.println(JSONObject.toJSONString(data, JSONWriter.Feature.PrettyFormat));
        } else {
            System.out.println(result.getMsg());
        }
    }
}
